import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:moose_app/core/model/poetry_model.dart';
import 'package:moose_app/ui/screens/discovery/recommend/recommend_item.dart';
import 'package:moose_app/ui/values/values.dart';

import 'recommend_banner.dart';

class ATHRecommendContent extends StatefulWidget {
  @override
  _ATHRecommendContentState createState() => _ATHRecommendContentState();
}

class _ATHRecommendContentState extends State<ATHRecommendContent> {
  EasyRefreshController _easyRefreshController;

  // 条目总数
  int _count = 2;

  @override
  void initState() {
    super.initState();
    _easyRefreshController = EasyRefreshController();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: kCommonMarin,
      child: EasyRefresh.custom(
          enableControlFinishRefresh: true,
          enableControlFinishLoad: true,
          controller: _easyRefreshController,
          header: MaterialHeader(),
          footer: MaterialFooter(),
          onRefresh: () async {
            await Future.delayed(Duration(seconds: 2), () {
              _easyRefreshController.finishRefresh(success: true);
            });
          },
          onLoad: () async {
            await Future.delayed(Duration(seconds: 2), () {
              setState(() {
                _count += 2;
              });
              _easyRefreshController.finishLoad(noMore: _count >= 10);
            });
          },
          slivers: [
            SliverToBoxAdapter(
              child: ATHRecommendBanner(),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate((context, index) {
                return ATHRecommendItem(
                  poetryItemModel: PoetryItemModel(
                      author: "李白",
                      title: "将进酒·君不见黄河之水天上来",
                      body:
                          "君不见黄河之水天上来，奔流到海不复回。\n君不见高堂明镜悲白发，朝如青丝暮成雪。\n人生得意须尽欢，莫使金樽空对月。\n天生我材必有用，千金散尽还复来。\n烹羊宰牛且为乐，会须一饮三百杯。\n岑夫子，丹丘生，将进酒，杯莫停。\n与君歌一曲，请君为我倾耳听。\n钟鼓馔玉不足贵，但愿长醉不复醒。\n古来圣贤皆寂寞，惟有饮者留其名。\n陈王昔时宴平乐，斗酒十千恣欢谑。\n主人何为言少钱，径须沽取对君酌。\n五花马，千金裘，\n呼儿将出换美酒，与尔同销万古愁。"),
                );
              }, childCount: _count),
            )
          ]),
    );
  }
}
